package com.szit.test.biz.impl;

import com.szit.test.biz.UserBiz;
import com.szit.test.dao.UserDao;
import com.szit.test.dao.impl.UserDaoImpl;
import com.szit.test.entity.User;

/**
 * 功能：用户业务逻辑层类
 *
 * @author 勇哥
 * @version 1.0 2025-05-25
 */
public class UserBizImpl implements UserBiz {
    private UserDao udao;

    public UserBizImpl() {
        udao = new UserDaoImpl();
    }

    @Override
    public int login(User user) {
        int flag = -1;

        User returnUser = udao.getUserByUsername(user.getUsername());

        if(returnUser!=null){
            // 判断密码是否正确
            if(returnUser.getPassword().equals(user.getPassword())) {
                flag = 1;
                user.setId(returnUser.getId());
            } else {
                flag = 0;
            }
        }

        return flag;
    }
}
